import javax.jms.*;
import javax.swing.*;

import org.apache.activemq.ActiveMQConnectionFactory;


public class printConsumer{
    private static String brokerURL = "tcp://localhost:61616";
    private static ConnectionFactory factory;
    private Connection connection;
    private Session session;
    private Topic topic1;
    private Topic topic2;
    private MessageConsumer messageConsumer1;
    private MessageConsumer messageConsumer2;
    private printListen listener1;
    private analyseListen listener2;

    //构造方法
    public printConsumer(String topicName1,String topicName2) throws JMSException {
        factory = new ActiveMQConnectionFactory(brokerURL);
        connection = factory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        topic1 = session.createTopic(topicName1);
        topic2 = session.createTopic(topicName2);
        messageConsumer1 = session.createConsumer(topic1);
        messageConsumer2 = session.createConsumer(topic2);
        connection.start();
        listener1 = new printListen();
        messageConsumer1.setMessageListener(listener1);
        listener2 = new analyseListen();
        messageConsumer2.setMessageListener(listener2);

    }

    public void close() throws JMSException {
        if (connection != null) {
            connection.close();
        }
        if (session!=null){
            session.close();
        }
    }

    public static void main(String[] args) throws JMSException {
        printConsumer consumer = new printConsumer("randomSignal","analyseResult");
        try{
            System.out.println("Press any key to end 实时数据显示节点");
            System.in.read();   // Pause
        }catch (Exception e){
            ;
        }
        consumer.close();
    }


}
